package com.example.rightmost.controller.admin;

import com.example.rightmost.entity.Result;
import com.example.rightmost.entity.TopicCategory;
import com.example.rightmost.service.CategoryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author:javayhch
 * @date:2024/8/20
 * @description:
 */

@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    public CategoryService categoryService;

    //获取所有分类（一级菜单）
    @RequestMapping("/getCategoryList")
    public PageInfo getCategoryList(@RequestParam(defaultValue = "1") int page,
                                    @RequestParam(defaultValue = "5") int size,
                                    @RequestBody TopicCategory category
    ){
        PageHelper.startPage(page, size);
        List<TopicCategory> list = categoryService.getCategoryList(category);
        PageInfo<TopicCategory> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    //添加分类
    @RequestMapping("/addCategory")
    public Result addCategory(@RequestParam String name){
        return categoryService.addCategory(name);
    }

    //修改分类
    @RequestMapping("/updateCategory")
    public Result updateCategory(@RequestBody TopicCategory category){
        return categoryService.updateCategory(category);
    }

    //删除分类
    @RequestMapping("/deleteCategory")
    public Result deleteCategory(@RequestParam int id){
        return categoryService.deleteCategory(id);
    }

    //启用，禁用分类
    @RequestMapping("/updateStatus")
    public Result updateStatus(@RequestParam int id){
        return categoryService.updateStatus(id);
    }

}
